<template>
	<view>
		<view class="u-m-t-250 u-m-l-30">
			<view class="Title">HELLO！</view>
			<view class="Title">绑定手机号！</view>
		</view>
		<view class="LoginForm">
			
			<view class="u-m-t-50 flex LoginForm_title" >
				<image src="/static/pages_login/account.png" mode=""></image>
				<text>手机号</text>
			</view>
			<view class="inputbox flex" >
				<input type="number" placeholder="请输入手机号" v-model="mobile" placeholder-class="ppp">
				<view class="wrap flex" style="align-items: center;">
					<view class="shu u-m-r-20">
						
					</view>
					<u-toast ref="uToast"></u-toast>
					<u-code :seconds="seconds"  ref="uCode" @change="codeChange"></u-code>
					<text class="green" @tap="getCode">{{tips}}</text>
				</view>
			</view>
			<view class="u-m-t-50 flex LoginForm_title">
				<image src="/static/pages_login/yzm.png" mode=""></image>
				<text>验证码</text>
			</view>
			<view class="inputbox">
				<input type="number" maxlength="4" placeholder="请输入验证码" v-model="code" placeholder-class="ppp">
			</view>
			
			<view class="mianbtn" @click="bind">
				绑定
			</view>
			
		</view>
		

	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: '',
				yzm:'',
				pwd: '',
				mobile:'',
				read: 1,
				register: 0,
				tips: '',
				seconds: 60,
				token: ''
			};
		},
		onLoad(option) {
			this.token = option.token
		},
		methods: {
			bind(){
				this.$api.post('/bind', {
					mobile: this.mobile,
					code: this.code,
				},{
					custom:{
						token: this.token
					}
				}).then(res => {
					if (res.code == 1) {
						uni.setStorageSync('token', this.token);
						uni.reLaunch({
							url: '/pages/index/index',
						})
					}
				})
			},
			codeChange(text) {
				this.tips = text;
			},
			getCode() {
				if (this.$refs.uCode.canGetCode) {
					if (!(/^1[3456789]\d{9}$/.test(this.mobile))) {
						uni.$u.toast('请输入正确的手机号');
						return;
					}
					this.$api.post('/sms', {
						event: 'bind',
						mobile: this.mobile,
					}).then(res => {
						if (res.code == 1) {
							this.$refs.uCode.start();
						}
					}).catch((res) => {
					})
					
				} else {
					uni.$u.toast('倒计时结束后再发送');
				}
			},
			
		}
	}
</script>

<style lang="scss">
	page {
		background-image: url('/static/pages_login/bg.png');
		width: 100vw;
		background-size: cover;
		background-position: center;
		background-repeat: no-repeat;
		box-sizing: border-box;
		overflow: auto;
	}

	.Title {
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #18274A;
		font-size: 56rpx;
	}

	.LoginForm {
		background-color: #fff;
		border-radius: 30rpx;
		padding: 30rpx;
		box-sizing: border-box;
		width: 90vw;
		margin: 50rpx auto;

		.LoginForm_title {
			font-size: 28rpx;

			image {
				width: 32rpx;
				height: 32rpx;
				margin-right: 20rpx;
			}
		}

		.inputbox {
			background-color: #F8FAFB;
			border-radius: 40rpx;
			padding: 20rpx 20rpx 20rpx 40rpx;
			width: 90%;
			margin: 30rpx auto;
			justify-content: space-between;
			.green {
				font-size: 28rpx;
				color: #00CE9B;
			}
			.shu{
				width: 3rpx;
				height: 30rpx;
				background-color: #00CE9B;
			}
			.ppp {
				font-size: 28rpx;
			}
		}
	}

	.mianbtn {
		width: 90%;
		font-size: 28rpx;
		color: #fff;
		background-color: #00CE9B;
		text-align: center;
		padding: 30rpx 0;
		margin: 50rpx auto 30rpx;
		border-radius: 40rpx;
	}

	.register {
		font-size: 28rpx;

		text {
			&:nth-child(1) {
				color: #B4BABE;
			}

			&:nth-child(2) {
				color: #00CE9B;
			}
		}
	}

	.bottom {
		width: 100vw;
		font-size: 28rpx;
		position: fixed;
		bottom: 100rpx;

		.circle {
			width: 28rpx;
			height: 28rpx;
			border: 2rpx solid #999;
			border-radius: 50%;
		}

		.green {
			color: #00CE9B;
		}
	}
</style>